################################################################################
# REPLICATION FILE FOR ELECTION OUTCOMES AND THE DIGESTION OF GRIEVANCE#########
# NICHOLAS KUIPERS##############################################################
# JOURNAL OF POLITICS###########################################################
################################################################################

rm(list = ls())

#set working directory to downloaded replication file
setwd("~/Dropbox/candidate_democracy/kuipers_replication_file")

library(gtsummary)
library(estimatr)
library(foreign)
library(tidyverse)
library(stargazer)
library(lmtest)
library(sandwich)
library(haven)
library(ggh4x)
library(gtable)
library(modelsummary)
library(kableExtra)
library(gt)
library(magrittr)
library(ggpubr)
library(fixest)
library(broom)
library(did)
library(ggforce)

#load helper functions
source("./code/_functions.R")

#LOAD OBJECT NAMES TO KEEP AFTER EACH SCRIPT
keep_objs = c("estimation_data", "write_latex_placebo", "keep_objs")

#make data
source("./code/1_clean_data.R")
rm(list=setdiff(ls(), keep_objs)) #clean up environment


################################################################################
#MAKE MAIN PAPER FIGURES AND TABLES#############################################
################################################################################

source("./code/2_figure_1a_1b.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/2_figure_2.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/2_table_1.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/2_table_2.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

################################################################################
#MAKE APPENDIX PAPER FIGURES AND TABLES#########################################
################################################################################

source("./code/3_figure_a1.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_figure_a2.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_figure_a3.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_figure_a4.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_figure_a5.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_figure_a6.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_figure_a7.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_figure_a8.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_figure_a9.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_figure_a10.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment


source("./code/3_table_a1.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_table_a2.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_table_a3.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_table_a4.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_table_a5.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_table_a6.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_table_a7.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_table_a8.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_table_a9.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_table_a10.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_table_a11.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_table_a12.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_table_a13.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_table_a14.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_table_a15.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

source("./code/3_table_a16.R",echo=T)
rm(list=setdiff(ls(), keep_objs)) #clean up environment

print(sessionInfo())
